package com.yunshipei.ui.dialog;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.yunshipei.enterplorer.R;

public class XCloudLoading extends WaitDialog {

    private ImageView ivLoading;

    public XCloudLoading(Context context) {
        super(context);
    }

    public XCloudLoading(Context context, int defStyle) {
        super(context, defStyle);
    }

    protected XCloudLoading(Context context, boolean cancelable, OnCancelListener listener) {
        super(context, cancelable, listener);
    }

    @Override
    protected void init(Context context) {
        setCancelable(false);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = View.inflate(context, R.layout.browser_loading_dialog_layout, null);
        ivLoading = (ImageView) view.findViewById(R.id.iv_loading);
        _messageTv = (TextView) view.findViewById(R.id.waiting_tv);
        setContentView(view);
    }

    @Override
    public void show() {
        super.show();
        ((AnimationDrawable) ivLoading.getDrawable()).start();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        ((AnimationDrawable) ivLoading.getDrawable()).stop();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        window.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
        lp.dimAmount = 0.5f;
        int screenHeight = window.getWindowManager().getDefaultDisplay().getHeight();
        lp.y = (int) (screenHeight * 0.3);
        onWindowAttributesChanged(lp);
        window.setAttributes(lp);
    }
}
